package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.pojo.Message;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
@Mapper
public interface MessageMapper extends BaseMapper<Message> {
    // 分页查询消息（按时间倒序）
    List<Message> selectByReceiver(
            @Param("receiverId") Integer receiverId,
            @Param("receiverType") String receiverType,
            @Param("offset") Integer offset,
            @Param("pageSize") Integer pageSize
    );
    // 统计未读消息数量
    Integer countUnread(@Param("receiverId") Integer receiverId,  @Param("receiverType") String receiverType);

    // 标记单个为已读
    void markAsRead(@Param("messageId")Integer messageId,@Param("receiverId") Integer receiverId, @Param("receiverType") String receiverType);

    // 标记全部为已读
    void markAllAsRead(@Param("receiverId") Integer receiverId, @Param("receiverType") String receiverType);

    @Delete("DELETE FROM message WHERE create_time < #{oldDate}")
    int deleteOldMessages(@Param("oldDate") String oldDate);
}
